export async function requestedMessage(callback, param = {}) {
    let options = {
        showSuccess: true,
        fullscreenLoading: true,
        errorHandle: undefined,
        finalHandle: undefined,
        ...param,
    };

    const loading = options.fullscreenLoading && window.$loadingBar?.start()
    try {
        const msg = await callback();
        console.log("数据" + msg);
        //关闭进度条
        window.$loadingBar.finish();
        // 处理成功消息
        let successMsg = msg;
        if (typeof msg === 'object' && msg !== null) {
            successMsg = msg.message || msg.msg || JSON.stringify(msg);
        }
        //提示成功
        options.showSuccess && window.$message.success(successMsg)
    } catch (error) {
        console.log("错误信息：" + error);
        if (error?.name === "CanceledError") {
            return;
        }
        options.errorHandle && options.errorHandle.call(this, error);
        let errorMsg = error;
        if (typeof error === 'object' && error !== null) {
            errorMsg = error.message || error.msg || error.errorMessage || JSON.stringify(error);
        }
        window.$message.error(errorMsg);
        //关闭进度条
        window.$loadingBar?.error();
    } finally {
        //关闭进度条
        loading && window.$loadingBar?.error()
        options.finalHandle && options.finalHandle();
    }
}